#ifndef graph_HPP
#define graph_HPP

#include <stdexcept>
#include <vector>

using namespace std;
namespace Graph{
template <class C>
struct my_graph{
       C node;
       //int PR;
       vector<C> connect;
       //vector<int> weight;
};
template <class C>
class graph
{
   public:
      my_graph<C> add_node(C node, vector<C> connect, int quantity){
           my_graph<C> elm;
           elm.node = node;
           //elm.PR = 1;
           elm.connect = connect;
           //for(int i = 0; i > connect.size(); i++){
           //   elm.weight[i] = 1;
           //}
           return elm;
      }
      void upload_graph(my_graph<C> m[], int quantity){
           FILE *fp;
           vector<C> tmp;
           fp = fopen("graph.dot", "w");
           fputs("digraph G{\n", fp);
           for(int i = 0; i < quantity; i++){
              tmp = m[i].connect;
              for(int it = tmp.size(); it > 0; it--){
                 fprintf(fp, "%d ->", m[i].node);
                 fprintf(fp, "%d;\n", tmp[it - 1]);
              }
           }
           fputs("}", fp);
           fclose(fp);
      }
      my_graph<C> click(my_graph<C> m[], int quantity){
           my_graph<C> n[quantity];
		   for(int i = 0; i < quantity; i++){
              n[i] = search_click(m,m[i],m[i],quantity,1);
           return n[i];
		   }
            
      }
      my_graph<C> search_click(my_graph<C> m[], my_graph<C> h2, my_graph<C> h, int quantity,int q_rec){  
         my_graph<C> result, n[quantity];
         vector<C> vec;
            vec = h.connect;
         for(int ij = 0; ij < vec.size(); ij++){
            for(int k; k < quantity; k++){
               if((vec[ij] == m[k].node)&&(q_rec < 2)){
                  q_rec++;
                  result = search_click(m,h2,m[k],quantity,q_rec);
               }
            }
         }
         int i = 0;
         for(int ij = 0; ij < (result.connect).size(); ij++){
            if(result.connect[ij] == h2.node){
               n[i].node = h2.node*100;
               n[i].connect = result.connect;
               return n[i]; 
			}
         }
         }		 
};
}
#endif
